#!/usr/bin/python2.4
#
# Copyright 2009-2010 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ========================================================================


Import('env')

#
# Build google_update_recovery library for Google app consumption.
#
rec_env = env.Clone(COMPONENT_LIBRARY_PUBLISH=True)
recovery_inputs = [
    'client/google_update_recovery.cc',
    '../base/signaturevalidator.cc',
    ]

# TODO(omaha3): Remove the dependency on common.lib since this library is
# designed to be consumed by apps that don't link with common.lib.
rec_env.Append(
    LIBS = [
        '$LIB_DIR/common.lib',
        ],
)

# Need to add custom suffix to avoid target conflict with
# common/signaturevalidator.obj
rec_env['OBJSUFFIX'] = '_rec' + rec_env['OBJSUFFIX']

rec_env.ComponentLibrary('google_update_recovery', recovery_inputs)

# Save the header to the main build directory, so we have it saved with each
# official build. The lib is already published to this directory.
rec_env.Replicate('$STAGING_DIR',
                  '$MAIN_DIR/recovery/client/google_update_recovery.h')

#
# Build the test
#
# TODO(omaha3): Switch entirely to hammer running tests. For now, we must make
# the test not runnable because it will be run during the build. See main.scons.
import os
if 'HAMMER_RUNS_TESTS' in os.environ.keys():
  test_env = env.Clone()
else:
  test_env = env.Clone(COMPONENT_TEST_RUNNABLE=False)

# This is a console application.
test_env.FilterOut(LINKFLAGS = ['/SUBSYSTEM:WINDOWS,5.01'])
test_env['LINKFLAGS'] += ['/SUBSYSTEM:CONSOLE,5.01']

test_env.Append(
    LIBS = [
        '$LIB_DIR/base.lib',
        '$LIB_DIR/net.lib',
        '$LIB_DIR/common.lib',
        '$LIB_DIR/crx_file.lib',
        '$LIB_DIR/google_update_recovery.lib',
        '$LIB_DIR/libprotobuf.lib',
        '$LIB_DIR/security.lib',
        test_env['atls_libs'][test_env.Bit('debug')],
        test_env['crt_libs'][test_env.Bit('debug')],
        'crypt32.lib',
        'wintrust.lib',

        # These are required by base.lib
        'netapi32.lib',
        'psapi.lib',
        'shlwapi.lib',
        'userenv.lib',
        'version.lib',
        'wtsapi32.lib',

        # net
        'iphlpapi.lib',
        ],
)

target_name = 'RecoveryTest'

test_inputs = [
    'recovery_test.cc',
    ]

# TODO(omaha): This test asserts when run so we cannot include it in
# run_all_tests. Fix it and consider adding to run_all_tests.
test_env.ComponentTestProgram(target_name,
                              test_inputs,
                              COMPONENT_TEST_DISABLED=True)


env.BuildSConscript('repair_exe')
